﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;


public class UIDisplayBarHealth : MonoBehaviour
{

    public GameObject barParent;
    public Image fillerMask;

    private RectTransform _rectTransform;

    public Vector2 offset = new Vector2(0f, -1f);
    // Start is called before the first frame update
    void Awake()
    {
        _rectTransform = GetComponent<RectTransform>();
    }

    // Update is called once per frame
    void Update()
    {
        if (GameManager.Instance.character)
        {
            
            float healthRatio = GameManager.Instance.character.GetHealthRatio();
            if (healthRatio < 0.999f && !GameManager.Instance.character.isDead)
            {
                barParent.SetActive(true);
                fillerMask.fillAmount = healthRatio;
                _rectTransform.anchoredPosition = GameManager.Instance.character.transform.position + (Vector3)offset;
            }
            else
            {
                barParent.SetActive(false);
            }

            
        }
        
        
    }
}
